package com.compass.aop;

import com.compass.service.ToolRecordService;
import com.compass.vo.BaseProtocol;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * User: li
 * Date: 2019/3/24
 * Time: 15:00
 * PROJECT：compass
 * PACKAGE: com.compass
 *
 * @author:55324936@qq.com To change this template use File | Settings | File Templates.
 */
@Aspect
@Component
@Slf4j
public class ToolAopConfig {

    @Autowired
    ToolRecordService toolRecordService;

    @Pointcut("execution(* com.compass.controller.tool.*.invoke(..))")
    public void executeService(){}
    //加入aop的目的，统计所有工具箱的小工具有多少人在使用，每天的调用次数以及工具类型，用于度量
    @AfterReturning(value = "executeService()",returning="result")
    public void after(JoinPoint joinPoint,Object result){
        Object[] objects=joinPoint.getArgs();
        Object paramObj =objects[0];
        toolRecordService.record((BaseProtocol) paramObj);
    }
}
